﻿
namespace EventBusNet6
{
    public class RabbitMQHelper
    {
        /// <summary>
        /// 获取RabbitMQ连接对象方法（创建与RabbitMQ的连接）
        /// </summary>
        /// <returns></returns>
        public static IConnection GetConnection()
        {
            //创建连接工厂【设置相关属性】
            var connectionFactory = new ConnectionFactory()
            {
                //设置IP
                HostName = "127.0.0.1",//RabbitMQ地址
                Port = 5672,//端口
                VirtualHost = "/test",//RabbitMQ中要请求的VirtualHost名称
                UserName = "test",//RabbitMQ用户
                Password = "123456"//RabbitMQ用户密码
            };
            //通过工厂创建连接对象
            return connectionFactory.CreateConnection();
        }
    }
}
